package com.example.admin;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.admin.activity.ForumMineActivityAd;
import com.example.admin.adapter.AdminHomeAdapter;
import com.example.admin.base.BaseActivity;
import com.example.admin.fragment.Tab0Fragment;
import com.example.admin.fragment.Tab1Fragment;
import com.example.admin.fragment.Tab2Fragment;
import com.example.admin.fragment.Tab3Fragment;
import com.example.admin.fragment.Tab4Fragment;
import com.example.admin.fragment.Tab5Fragment;
import com.example.admin.fragment.Tab6Fragment;
import com.example.admin.fragment.TabFragment;

import java.util.ArrayList;
import java.util.List;

public class AdminActivity extends BaseActivity {
    AdminHomeAdapter mAdapter;
    RecyclerView recyclerView;
    TextView tvTitle, tvSC;

    @Override
    public void setContentView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_admin);
        tvTitle = findViewById(R.id.tvTitle);
        addFragments(new TabFragment());
        mAdapter = new AdminHomeAdapter();
        recyclerView = findViewById(R.id.recyclerView);
        tvSC = findViewById(R.id.tvSC);
        recyclerView.setAdapter(mAdapter);
        List<String> list = new ArrayList<>();
        //list.add("用户信息");
        list.add("社区通知");
        list.add("费用缴约");
        list.add("社区论坛");
        list.add("意见反馈");
        list.add("社区活动");
        list.add("个人中心");
        mAdapter.setNewData(list);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                mAdapter.setPoin(position);
                tvTitle.setText(mAdapter.getItem(position));
                tvSC.setVisibility(View.GONE);
                switch (position) {

                    case 0:
                        addFragments(new Tab1Fragment());
                        break;
                    case 1:
                        addFragments(new Tab2Fragment());
                        break;
                    case 2:
                        addFragments(new Tab3Fragment());
                        tvSC.setVisibility(View.VISIBLE);
                        break;
                    case 3:
                        addFragments(new Tab4Fragment());
                        break;
                    case 4:
                        addFragments(new Tab5Fragment());
                        break;
                    case 5:
                        addFragments(new Tab6Fragment());
                        break;
                }
            }
        });
        tvSC.setOnClickListener(v -> {
            startActivity(new Intent(this, ForumMineActivityAd.class));
        });
    }

    @Override
    public void setInitView() {

    }

    private void addFragments(Fragment fragment) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.contenLayout, fragment);
        transaction.commit();
    }
}